function GetRequest(){
	var url = location.search;
	var theRequest = new Object();
	if(url.indexOf("?" != -1)){
		var str = url.substr(1);
		strs = str.split("&");
		for(var i = 0;i < strs.length;i++){
			theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
		}
	}
	return theRequest;
}
var Request = new Object();
Request = GetRequest();
var totalRows = Request['totalRows'];
if(totalRows==undefined){
	totalRows=0;
}
$("#endRow").val(totalRows);
$("#exportSpan").html("(共"+totalRows+"条)");
$("#totalRows").val(totalRows);
$(function() {
	initForm();
});

/**
 * 初始化表单
 */
function initForm() {

	// 表单Id
	formId = "mainForm";
	// 验证规则
	/*rules = {
		startRow : {
			digits: true
		},
		endRow : {
			digits: true
		}
	};*/
	commonInitForm();
}
//开始导出文件
$("#startExport").click(function(){
	
	var cols = '';
	$(':checked').each(function(){
		cols += ',' + $(this).val();
	});
	
	if(cols){
		cols = cols.substring(1);
	}
	
	var startRow = $("#startRow").val();
	var endRow = $("#endRow").val();
	var maxRow = parseInt($("#maxRow").val());
	var totalRows = parseInt($("#totalRows").val());
	var exportType = $("#exportType").val();
	
	//需要验证 必须是数字
	if(totalRows == 0) {
		$("#warnMsg").text('* 当前没数据可导出！');
		return;
	}else if(startRow == '' || endRow == '') {
		$("#warnMsg").text('* 请输入导出范围！');
		return;
	}else {
		if(!isPInt(startRow) || !isPInt(endRow)) {
			$("#warnMsg").text('* 请输入大于0的整数！');
			return;
		}else if(totalRows < parseInt(startRow)) {
			$("#warnMsg").text('* 导出数据超出了范围！');
			return;
		}else if(parseInt(endRow) < parseInt(startRow)) {
			$("#warnMsg").text('* 后数字不能小于前数字！');
			return;
		}else {
			$("#warnMsg").text('');
			startRow = startRow < 1? 0:startRow - 1;
			maxRow = endRow - startRow;
		}
	}
	
	parent.exportColConfigSelectCallback(cols,startRow,maxRow,exportType);
	//关闭下载对话框
	parent.layer.close(parent.layer.getFrameIndex(window.name));
	
});

//全选功能
$("#selectAll").click(function(){
	
	$('.icheckbox_square-green').each(function(){
		$(this).removeClass("icheckbox_square-green");
		$(this).addClass('icheckbox_square-green checked');
		$(this).find('input').attr("checked","checked");
	});
	
});

//不选功能
$("#selectNot").click(function(){
	
	$('.icheckbox_square-green').each(function(){
		$(this).removeClass("icheckbox_square-green checked");
		$(this).addClass('icheckbox_square-green');
		$(this).find('input').removeAttr('checked');
	});
	
});


//验证文本框数字
function isPInt(str) {
    var g = /^[1-9]*[1-9][0-9]*$/;
    return g.test(str);
}



